<%@ page language="java" contentType="text/html; charset=utf-8"%>
<html>
<head>
<%@ include file="/extjs/include/all.jsp"%>
<title>日志管理</title>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/extjs/css/file-upload.css" />
<script type="text/javascript" src="${pageContext.request.contextPath}/extjs/js/FileUploadField.js"></script>
</head>
<body>
<div id="sysBundlesForm" style="width:100%"></div>
<div id="dictListForm" style="width:100%"></div>
<div id="insertOrganForm" style="width:100%"></div>
<div id="upLoadForm" style="width:100%"></div>
</body>
</html>
<script type="text/javascript">
function bundleStart(key){
	window.location = "<%=request.getContextPath()%>/edu.ccut.saturn.manager.bundles.impl::/extBundleModule/appBundleAction/InstallBundle.action?key="+key;
}
function bundleStop(key){
	window.location = "<%=request.getContextPath()%>/edu.ccut.saturn.manager.bundles.impl::/extBundleModule/appBundleAction/UninstallBundle.action?key="+key;
}
function bundleInfo(key){
	window.location = "<%=request.getContextPath()%>/edu.ccut.saturn.manager.bundles.impl/extComponentModule/page/bundleInfo.jsp?key="+key;
}
Ext.onReady(function(){
  	var sysBundleStore = new Ext.data.JsonStore({
		url: '${pageContext.request.contextPath}/edu.ccut.saturn.manager.bundles.impl::/extBundleModule/appBundleAction/QueryBundlesbyCondition.action',
		root: 'sysBundleList',
		totalProperty:'sysCount',
		fields: [
			{name:'key'},
			{name:'symbolicName'},
			{name:'version'}
		]
	});   
	sysBundleStore.load({params:{start:0,limit:10}});
	
	var appBundleStore = new Ext.data.JsonStore({
		url: '${pageContext.request.contextPath}/edu.ccut.saturn.manager.bundles.impl::/extBundleModule/appBundleAction/QueryBundlesbyCondition.action',
		root: 'appBundleList',
		totalProperty:'appCount',
		fields: [
			{name:'key'},
			{name:'symbolicName'},
			{name:'version'},
			{name:'status'}
		]
	});   
	appBundleStore.load({params:{start:0,limit:10}});
	
	var resultWidth = Ext.get("sysBundlesForm").getWidth();
	var sysBundleModel = new Ext.grid.ColumnModel([ 
	    new Ext.grid.RowNumberer(), 
        {header:'名称',dataIndex:'key',width:resultWidth*0.33,sortable:true}, 
        {header:'标识',dataIndex:'symbolicName',width:resultWidth*0.33,sortable:true}, 
        {header:'版本',dataIndex:'version',width:resultWidth*0.30,sortable:true}
    ]); 
       
	var sysBundleGrid = new Ext.grid.GridPanel({ 
	    el:'sysBundlesForm', 
	    title:'系统bundles', 
	    autoHeight:true,
	    stripeRows: true,
	    collapsible:true,
	    bodyStyle:'width:100%',
	    trackMouseOver:false, 
	    loadMask: {msg:'正在加载数据，请稍侯……'}, 
	    store:sysBundleStore, 
	    cm: sysBundleModel,
	    bbar:new Ext.PagingToolbar({
	    		pageSize:10,
	    		store:sysBundleStore,
	    		displayInfo:true,
	    		displayMsg:'当前显示 {0} - {1}条记录 /共 {2}条记录', 
	    		emptyMsg:'没有数据显示'
	    	})
	    
	}); 
	
    sysBundleGrid.render(); 	
    
    var dictListForm = new Ext.FormPanel({
        frame:true,
        title: '查询应用bundles',
        bodyStyle:'padding:5px 5px 0',
        collapsible:true,
        bodyStyle:'width:100%',
        renderTo:'dictListForm', 
        items: [{
	            layout:'column',
	            items:[{
	                columnWidth:.5,
	                layout: 'form', 
	                items: [{
	                    xtype:'textfield',
	                    fieldLabel: 'bundle名称',
	                    name: 'name',
	                    id:'name',
	                    anchor:'95%'
                	}]
            		},{
	                columnWidth:.5,
	                layout: 'form',
	                items: [{
	                    xtype:'textfield',
	                    fieldLabel: 'bundle标识',
	                    name: 'key',
	                    id: 'key',
	                    anchor:'95%'
	                }]
	            }]
        }],

        buttons: [{
            text: '查询',
            handler:function(){
            	if (dictListForm.form.isValid()) {
		       		appBundleStore.load({params:{						
							name:Ext.get("name").dom.value,
							key:Ext.get("key").dom.value,
							start:0,
							limit:10
					}}); 
		       		appBundleGrid.getView().refresh();
       			} else {
       				Ext.MessageBox.alert('警告','对不起,您的页面输入有误');
       			}
            }
        }]
    });
    
    var appBundleModel = new Ext.grid.ColumnModel([ 
	    new Ext.grid.RowNumberer(), 
        {header:'名称',dataIndex:'key',width:resultWidth*0.25,sortable:true,renderer:function(value,p,record){
        	return '<a href="javascript:bundleInfo(\''+record.data.symbolicName+'\')">'+value+'</a>';
        }}, 
        {header:'标识',dataIndex:'symbolicName',width:resultWidth*0.25,sortable:true}, 
        {header:'版本',dataIndex:'version',width:resultWidth*0.25,sortable:true},
        {header:'操作',dataIndex:'status',width:resultWidth*0.20,sortable:true,renderer:function(value,p,record){
       		if('enable' == value){
       			return 	'启动&nbsp;&nbsp;|&nbsp;&nbsp;<a href="#" onclick="bundleStop(\''+record.data.key+'\')">停止</a>';
       		} else {
       			return 	'<a href="#" onclick="bundleStart(\''+record.data.key+'\')">启动</a>&nbsp;&nbsp;|&nbsp;&nbsp;停止';
       		}
        }}
    ]); 
       
	var appBundleGrid = new Ext.grid.GridPanel({ 
	    el:'insertOrganForm', 
	    title:'应用bundles', 
	    autoHeight:true,
	    stripeRows: true,
	    collapsible:true,
	    bodyStyle:'width:100%',
	    trackMouseOver:false, 
	    loadMask: {msg:'正在加载数据，请稍侯……'}, 
	    store:appBundleStore, 
	    cm: appBundleModel,
	    bbar:new Ext.PagingToolbar({
	    		pageSize:10,
	    		store:appBundleStore,
	    		displayInfo:true,
	    		displayMsg:'当前显示 {0} - {1}条记录 /共 {2}条记录', 
	    		emptyMsg:'没有数据显示'
	    	})
	    
	}); 
	appBundleGrid.render(); 
		
	var upLoadForm = new Ext.FormPanel({
        frame:true,
        title: '上传bundles',
        fileUpload: true,
        bodyStyle:'padding:5px 5px 0',
        collapsible:true,
    //    bodyStyle:'width:100%',
        renderTo:'upLoadForm', 
        items: [{
	            xtype: 'fileuploadfield',
	            id: 'file',
	            name: 'file',
	            emptyText: '请选择bundle...',
	            fieldLabel: '选择bundle',
	            anchor: '95%' ,
	            fileUpload: true,
	            allowBlank: false,
	            buttonCfg: {
	                text: '浏览..'
	            }
            }],
        buttons: [{
            text: '上传',
            handler: function(){
                if(upLoadForm.form.isValid()){
                	var form = upLoadForm.getForm().getEl().dom;
                	form.action = '${pageContext.request.contextPath}/edu.ccut.saturn.manager.bundles.impl::/extBundleModule/appBundleAction/UpLoadAppBundle.action';
                	form.target = '_self';
                	form.submit();
                } else {
                	Ext.MessageBox.alert('提示','请选择bundle');
                }
            } 
        }]
    });
});
</script>